<template>
  <div class="collection">
    <div class="type">
      <div class="type-head">
        <el-image class="type-text" :src="require('@/assets/logo/logoH.png')"/>
      </div>

      <div class="cartButton" :style="moreCart ? {borderBottom:'none', backgroundColor: 'white'} : {}" v-on:mouseenter="getCartItem()" v-on:mouseleave="moreCart = false">
        <span class="pushCart">我的购物车</span>
        <el-badge :value="cartList.length" class="item" style="font-size: 20px;height: 20px;line-height: 20px;">
          <i class="el-icon-shopping-cart-1" style="margin-left: 10px"></i>
        </el-badge>
      </div>
      <div id="moreCart" class="moreCart" v-show="moreCart" v-on:mouseover="moreCart = true" v-on:mouseout="moreCart = false">
        <div class="moreCartProduct">
          <div style="text-align: left;padding-left: 10px;margin-top: 10px;margin-bottom: 10px;font-size: 13px;font-weight: bold">最新加入的商品</div>
          <div class="moreCartDetail" v-for="item in cartList" :key="item.skuId">
            <el-image
              class="moreCartDetailImg"
              :src="item.skuImg"
              @click="pushProductDetail(item.skuId)"
              fit="cover"></el-image>
            <div class="moreCartDetailTitle" @click="pushProductDetail(item.skuId)">{{ item.skuTitle }}</div>
            <div style="float: right;font-size: 12px;text-align: right">
              <div><span style="color: red">￥{{ item.skuPrice }}.00</span>×{{ item.count }}</div>
              <div class="moreCartDetailDel" @click="delCartItem(item.skuId)">删除</div>
            </div>
          </div>
        </div>
        <div class="moreCartBottom">
          <span style="font-size: 12px">共{{ cartList.length }}件商品</span>
          <div class="morePushCart"  @click="$router.push({path: '/cart'})">去购物车</div>
        </div>
      </div>

      <form class="find-button">
        <input class="find-input" type="text" placeholder="请输入您要搜索的内容..." v-model="searchText">
        <button class="find-click" type="submit" @click="searchButton()"><i class="el-icon-search"/></button>
      </form>
    </div>

    <div class="main">

      <div class="success-wrap">
        <div class="w" id="result">
          <div class="m succeed-box">
            <div class="mc success-cont">

              <div class="success-lcol" style="display: inline-block">
                <div class="success-top"><b class="succ-icon"></b>
                  <h3 class="ftx-02">商品已成功加入购物车</h3></div>
                <div class="p-item">
                  <div class="p-img" style="display: inline-block;float: left">
                    <a @click="pushProductDetail(list.skuId)" target="_blank"><img style="height: 60px;width:60px;" :src="list.skuImg"></a>
                  </div>
                  <div class="p-info" style="display: inline-block;float:left;">
                    <div class="p-name" style="margin-left: 20px;color: rgb(51,51,51);font-size: 17px">
                      <a class="skuTitle" @click="pushProductDetail(list.skuId)">{{ list.skuTitle }}</a>
                    </div>
                    <div class="p-extra" style="margin-left: 20px;color: rgb(177,170,177);font-size: 14px">
                      <span class="txt" style="margin-right: 10px" v-for="item in list.skuAttr" :key="item">{{ item }}</span>
                      <span class="txt" >/ 数量：{{ count }}</span>
                    </div>
                  </div>
                  <div class="clr"></div>
                </div>
              </div>

              <div class="success-btns success-btns-new" style="display: inline-block;float: right">
                <div class="success-ad">
                  <a href="/#none"></a>
                </div>
                <div class="clr"></div>
                <div class="bg_shop">
                  <a class="btn-tobback" @click="pushProductDetail(list.skuId)">查看商品详情</a>
                  <a class="btn-addtocart" id="GotoShoppingCart" @click="$router.push({path: '/cart'})"><b></b>
                    去购物车结算
                    <i class="el-icon-arrow-right"></i>
                  </a>
                </div>
              </div>

            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
import {Loading} from "element-ui";

export default {
  name: 'Success',
  data() {
    return {
      moreCart: false,
      searchText: '',
      cartList: [],
      list: {},
      count: 0
    }
  },
  created() {
    this.getProductDetail()
    this.getCartItem()
    this.moreCart = false
  },
  methods: {
    getCartItem(){
      this.moreCart = true
      let loadingService = Loading.service({
        target: '#moreCart',
        lock: true
      });
      this.$store.dispatch('cart/cart/getCartItem')
        .then((data)=>{
          this.cartList = data.data
          loadingService.close()
        })
        .catch(()=>{})
    },
    pushProductDetail(id){
      console.log(id)
      let routeData = this.$router.resolve({
        path: "/product-detail",
        query: {
          skuId: id
        }
      });

      //必要操作，否则不会打开新页面
      window.open(routeData.href, '_blank');
    },
    getProductDetail(){
      let data = this.$route.query.data
      if(data !== undefined){
       this.list = JSON.parse(this.$route.query.data)
       this.count = this.$route.query.count
        console.log(this.count)
      }else{
        this.$router.push({path: "/search"});
      }
    },
    searchButton(){
      if(this.searchText !== ''){
        let routeData = this.$router.resolve({
          path: "/search",
          query: {
            keyword: this.searchText
          }
        });

        //必要操作，否则不会打开新页面
        window.open(routeData.href, '_blank');
      }
    },
    delCartItem(skuId){
      this.$store.dispatch('cart/cart/delCartItem', skuId)
        .then(()=>{
          this.getCartItem()
        })
        .catch(()=>{})
    }
  }
}
</script>

<style lang="scss">
.el-card__body {
  padding: 0px;
}
.el-badge__content{
  background-color: rgb(60,133,39);
}
</style>

<style lang="scss" scoped>
.skuTitle{

  &:hover{
    color: rgb(60,133,39);
  }
}
.btn-tobback{
  margin-top: 83px;
  margin-right: 10px;
  width: 170px;
  height: 40px;
  background-color: white;
  border: 1px solid white;
  color: rgb(60,133,39);
  display: inline-block;
  line-height: 40px;
  text-align: center;

  &:hover{
    cursor:pointer;
    border: 1px solid rgb(60,133,39);
  }
}

.btn-addtocart{
  width: 170px;
  height: 40px;
  background-color: rgb(60,133,39);
  color: white;
  display: inline-block;
  line-height: 40px;
  text-align: center;

  &:hover{
    cursor:pointer;
  }
}

.collection {
  height: 848px;
  width: 100%;
  background-color: rgb(245, 245, 245);

  .type {
    width: 1300px;
    height: 80px;
    margin: 0 auto;
    text-align: center;
    //padding-top: 20px;
    //padding-bottom: 20px;

    .type-head {
      width: 130px;
      height: 80px;
      line-height: 80px;
      display: inline-block;
      float: left;

      .type-text {
        height: 50px;
        width: 130px;
        margin-top: 15px;
        //display: inline-block;
        //font-size: 16px;
        //margin-top: 13px;
        //margin-right: 20px;
        //float: left;

        &:hover {
          cursor: pointer;
          //color: rgb(79,159,52);
        }
      }
    }

    .cartButton{
      width: 150px;
      height: 42px;
      line-height: 42px;
      display: inline-block;
      float: right;
      margin-top: 19px;
      font-size: 13px;
      margin-left: 40px;
      border: 1px solid rgb(200, 200, 200);
      background-color: rgb(230, 230, 230);
      color: rgb(60,133,39);
      z-index: 51;
      position: relative;

      .pushCart{
        &:hover{
          cursor: pointer;
        }
      }
    }
    .moreCart{
      position: absolute;
      top: 60px;
      right: 301px;
      width: 350px;
      background-color: white;
      z-index: 50;
      border: 1px solid rgb(200,200,200);

      .moreCartProduct{


        .moreCartDetail{
          height: 70px;
          padding: 10px;

          .moreCartDetailImg{
            width: 50px;
            height: 50px;
            float: left;

            &:hover{
              cursor: pointer;
            }
          }

          &:hover{
            background-color: rgb(230,230,230);
          }
        }

        .moreCartDetailDel{
          margin-top: 5px;

          &:hover{
            cursor: pointer;
            color: rgb(60,133,39);
          }
        }

        .moreCartDetailTitle{
          display: inline-block;
          float: left;
          color: rgb(102,102,102);
          margin-left: 10px;
          text-align: left;
          width: 100px;
          height: 50px;
          line-height: 17.5px;
          font-size: 12px;
          text-overflow: ellipsis;
          -o-text-overflow: ellipsis;
          overflow: hidden;

          &:hover{
            cursor: pointer;
            color: rgb(60,133,39);
          }
        }
      }

      .moreCartBottom{
        height: 50px;
        background-color: rgb(230,230,230);

        span{
          display: inline-block;
          float: left;
          line-height: 50px;
          margin-left: 10px;
        }

        .morePushCart{
          float: right;
          width: 60px;
          height: 30px;
          line-height: 30px;
          text-align: center;
          margin-top: 10px;
          background-color: rgb(60,133,39);
          color: white;
          font-size: 12px;
          font-weight: bold;
          border-radius: 5px;
          margin-right: 10px;

          &:hover{
            cursor: pointer;
          }
        }
      }
    }

    .find-button {
      background-color: white;
      position: relative;
      width: 400px;
      float: right;
      //margin-right: 400px;
      border: 1px solid rgb(178,178,178);
      margin-top: 19px;

      .find-input {
        background: transparent;
        width: 100%;
        height: 42px;
        padding-left: 13px;
        padding-right:46px;
        border: none;
        outline: none;
        font-size: 10px;
      }

      .find-click {
        background: transparent;
        top: 0;
        right: 0;
        height: 42px;
        width: 42px;
        cursor: pointer;
        position: absolute;
        border: none;
        outline: none;
      }
    }
  }

  .main{
    background-color: rgb(230, 230, 230);

    .success-wrap{
      width: 1300px;
      margin: 0 auto;
      padding-bottom: 20px;
      border-top: 2px solid rgb(60,133,39);

      .success-top{
        color: rgb(60,133,39);
      }
    }
  }
}
</style>
